---
title: 
  | 
  | Replication Material
  | 
  | How Transnational Party Alliances Influence National Parties’ Policies 
  |
  | doi: 
author: "Roman Senninger, Daniel Bischof, and Lawrence Ezrow"
date: "Contact: rsenninger@ps.au.dk"
output: 
  bookdown::html_document2:
    theme: cosmo
    highlight: kate
    toc: true
    number_sections: false
    toc_float: 
     collapsed: false
     smooth_scroll: false
    code_folding: show
    fig_width: 5
    fig_height: 5 
---

```{r setup, include = F}
knitr::opts_knit$set(root.dir = '/Users/au506709/Dropbox/RomanDaniel/Daniel lead/Diffusion/data/replication_files/data/')
```

# Data

Please visit the PSRM dataverse (https://dataverse.harvard.edu/dataverse/PSRM) or Roman Senninger's Dataverse (https://dataverse.harvard.edu/dataverse/R_Senninger) to download the data sets used in this manual.   

# Load Required Packages

```{r, eval = T, echo = T, include= T, message= FALSE}

library("dplyr")
library("ggplot2")
library("stargazer")
library("lmtest")
library("Zelig")


```

# Set Seed

```{r, eval = T, echo = T, include= T, message= FALSE}

set.seed(12345678)

```

# Main Results 

This manual provides code to reproduce our results in the main body of the manuscript and the appendix. We start with the regression results in Table 1.


## Table 1

```{r, eval = T, echo = T, include=TRUE}

# load dataset 

load("./dataframe1.RData")

# increase maximum print to show full regression outputs 

options(max.print=1000000)

# capture all parties minus one from colnames to include party fixed effects in the models

partyfx <- paste(colnames(dataframe1[24:237]), sep="")

# Model 1 in Table 1

model1 <- as.formula(paste("rile ~  spruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse="+")))

model1 <- lm(model1, data = dataframe1)
summary(model1)
stargazer(model1)

# Model 2 in Table 2

model2 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 +  year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model2 <- lm(model2, data = dataframe1)
summary(model2)
stargazer(model2)

# Model 3 in Table 1

model3 <- as.formula(paste("rile ~ spsamegroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 +  year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model3 <- lm(model3, data = dataframe1)
summary(model3)
stargazer(model3)

# Model 4 in Table 1

model4 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model4 <- lm(model4, data = dataframe1)
summary(model4)
stargazer(model4)


# Model 5 in Table 1 

model5 <- as.formula(paste("rile ~  lag_rile + lag_cmedian + lag_econ_glob + interaction + spdiffgroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model5 <- lm(model5, data = dataframe1)
summary(model5)
stargazer(model5)

# Model 6 in Table 1 

model6 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled + spdiffgroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model6 <- lm(model6, data = dataframe1)
summary(model6)
stargazer(model6)

# Model 7 in Table 1

# The model is based on an updated dataset entiteled dataframe2

# load dataset 

load("./dataframe2.RData")

model7 <- as.formula(paste("rile ~ lag_rile + lag_cmean + lag_econ_glob + interaction + spsamegroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 + year_fe35 + year_fe36 + year_fe37 + year_fe38 + year_fe39 + year_fe40 + " , paste(partyfx, collapse= "+")))

model7 <- lm(model7, data = dataframe2)
summary(model7)
stargazer(model7)

```

## Figure 1 - left panel 
 
The left panel in Figure 1 is based on Model 4 and Model 5 in Tabel 1. As described in the article, the coefficients of the spatial lags are multiplied by the average number of neighbors. The results of the multiplications are stored in dataframe3 in the form of estimated short-term and long-term effects for our spatial lag variables. 

```{r, eval = T, echo = T, include= T, message= FALSE, fig.width=8, fig.height=4}

# load dataset 

load("./dataframe3.RData")

ggplot(dataframe3, aes(x=name, y=coefs, color=model, group=model)) + 
  geom_point(size=1, position=position_dodge(width=0.3)) +
  geom_errorbar(aes(ymin=li, ymax=ui), width=.01, position=position_dodge(width=0.3)) + 
  coord_flip() + theme_bw() + geom_hline(yintercept=0, linetype="dashed", 
                                         color = "gray50", size=0.5) +
  ylab("Spatial Effects") + xlab("") + theme(legend.title=element_blank()) +
  scale_color_manual(values=c("gray80", "gray50"), guide = guide_legend(reverse=TRUE)) +
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + ggtitle("Global Model") +
  ylim(-0.025, 0.025)

```

## Figure 1 - right panel 

The right panel in Figure 1 is based on Model D1-D4 in Table S3 which are fullt reproduced below (see Section Table S3). 

To reproduce the right panel of Figure 1, the coefficients of the spatial lags are muliplied with the average number of neighbors in the same manner as before. The results of the multiplications are stored in dataframe4 in the form of estimated long-term effects for our spatial lag variables. 

```{r, eval = T, echo = T, include= T, message= FALSE, fig.width=8, fig.height=4}

# load dataset 

load("./dataframe4.RData")

ggplot(dataframe4, aes(x= reorder(name, coefs), y= coefs)) + 
  geom_point(size=2, position=position_dodge(width=0.3), color = "gray80") +
  geom_errorbar(aes(ymin=li, ymax=ui), width=.01, position=position_dodge(width=0.3), color = "gray80") + 
  coord_flip() + theme_bw() + geom_hline(yintercept=0, linetype="dashed", 
                                         color = "gray50", size=0.5) +
  ylab("Spatial Effects") + xlab("") + theme(legend.title = element_blank()) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + ggtitle("Group Models") + 
  ylim(-0.15, 0.15) 


```

# Supplementary Information

In the following, we provide the code and data to reproduce the results in the supplementary material (SI). We follow the same order as in the SI. 


## Table S2

```{r, eval = T, echo = T, include= T, message= FALSE, fig.width=8, fig.height=4}

# load datasets 


load("./dyad_pes.RData")
load("./dyad_epp.RData")
load("./dyad_alde.RData")
load("./dyad_uen.RData")

pes <- dyad_pes %>% group_by(yearpartyidi)  %>%
  dplyr::summarize(sum = sum(samegroup_ruled))

mean(pes$sum)

epp <- dyad_epp %>% group_by(yearpartyidi)  %>%
  dplyr::summarize(sum = sum(samegroup_ruled))

mean(epp$sum)

alde <- dyad_alde %>% group_by(yearpartyidi)  %>%
  dplyr::summarize(sum = sum(samegroup_ruled))

mean(alde$sum)

uen <- dyad_uen %>% group_by(yearpartyidi)  %>%
  dplyr::summarize(sum = sum(samegroup_ruled))

mean(uen$sum)


```


## Table S3

```{r, eval = T, echo = T, include=TRUE}

# load datasets 

load("./dataframe_pes.RData")
load("./dataframe_epp.RData")
load("./dataframe_alde.RData")
load("./dataframe_uen.RData")

# increase maximum print to show full regression outputs 

options(max.print=1000000)

# capture all parties minus one from colnames to include party fixed effects in the models

partyfx <- paste(colnames(dataframe_pes[24:237]), sep="")

# Model D1 in Table S3

modeld1 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled_sd + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

modeld1 <- lm(modeld1, data = dataframe_pes)
summary(modeld1)
stargazer(modeld1)

# Model D2 in Table S3

modeld2 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled_epp + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

modeld2 <- lm(modeld2, data = dataframe_epp)
summary(modeld2)
stargazer(modeld2)

# Model D3 in Table S3

modeld3 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled_lib + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 +  year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

modeld3 <- lm(modeld3, data = dataframe_alde)
summary(modeld3)
stargazer(modeld3)

# Model D4 in Table S3

modeld4 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled_uen + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 +  year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

modeld4 <- lm(modeld4, data = dataframe_uen)
summary(modeld4)
stargazer(modeld4)

```

## Table S4

```{r, eval = T, echo = T, include=TRUE}

# load dataset

load("./dataframe_soc.RData")

# increase maximum print to show full regression outputs 

options(max.print=1000000)

# capture all parties minus one from colnames to include party fixed effects in the models

partyfx <- paste(colnames(dataframe_pes[24:237]), sep="")

# Model 1 in Table S4

model1 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spsameparfam_soc + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + 
year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + 
                          year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + 
                          year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model1 <- lm(model1, data = dataframe_soc)
summary(model1)
stargazer(model1)

#Model 2 in Table S4

model2 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spsameparfam_ruled_soc + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + 
year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + 
                          year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + 
                          year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model2 <- lm(model2, data = dataframe_soc)
summary(model2)
stargazer(model2)


```

## Figure S2 

```{r, eval = T, echo = T, include=TRUE, fig.width=10, fig.height=8}

# load datasets 

load("./dataframe_zelig.RData")

# left panel 

model1 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + 
year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

z1 <- zelig(model1, data = dataframe_zelig, model = "ls")

z1 <- setx(z1, spsamegroup_ruled  = 0.00)
z1 <- setx1(z1, spsamegroup_ruled = 47.39)
z1.out <- sim(z1)

x <- z1.out$get_qi(qi = "ev", xvalue="x")
x1 <- z1.out$get_qi(qi = "ev", xvalue="x1")

y <- x-x1

xd <- density(x)
xd1 <- density(x1)

plot(xd, main="", sub="",
     xlab="", ylab="",frame.plot=FALSE,
     xlim=c(5.2, 5.5), ylim=c(0, 60), cex.axis=1, las=1)
par(new= TRUE)
plot(xd1, main="", sub="",
     xlab="", ylab="",frame.plot=FALSE,
     xlim=c(5.2, 5.5), ylim=c(0, 60), cex.axis=1, las=1)
polygon(xd, col = "darkgray", border = "darkgray")
par(new= TRUE)
polygon(xd1, col = "lightgray", border = "lightgray")


# left panel 

model2 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spdiffgroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + 
year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

z1 <- zelig(model2, data = dataframe_zelig, model = "ls")

z1 <- setx(z1, spdiffgroup_ruled  = 0.00)
z1 <- setx1(z1, spdiffgroup_ruled = 129.97)
z1.out <- sim(z1)

x <- z1.out$get_qi(qi = "ev", xvalue="x")
x1 <- z1.out$get_qi(qi = "ev", xvalue="x1")

y <- x-x1

xd <- density(x)
xd1 <- density(x1)

plot(xd, main="", sub="",
     xlab="", ylab="",frame.plot=FALSE,
     xlim=c(5.2, 5.5), ylim=c(0, 60), cex.axis=1, las=1)
par(new= TRUE)
plot(xd1, main="", sub="",
     xlab="", ylab="",frame.plot=FALSE,
     xlim=c(5.2, 5.5), ylim=c(0, 60), cex.axis=1, las=1)
polygon(xd, col = "darkgray", border = "darkgray")
par(new= TRUE)
polygon(xd1, col = "lightgray", border = "lightgray")


```

## Figure S3 

```{r, eval = T, echo = T, include=TRUE, fig.width=10, fig.height=8}

# load datasets 

load("./dataframe1.RData")
load("./dataframe_equi.RData")


# run model with simulation data 
model_equi <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + 
year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + 
year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model_equi <- lm(model_equi, data = dataframe_equi)

# get predicted values from the original model 
model4 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model4 <- lm(model4, data = dataframe1)

orig.pred <- as.data.frame(predict(model4))
new.pred <- as.data.frame(predict(model_equi))
names(orig.pred) <- c("fit")
names(new.pred) <- c("fit")

# compute difference between the predicted values
effect <- new.pred$fit - orig.pred$fit
el <- data.frame(party_id = dataframe_equi$party_id, groupnumber = dataframe_equi$groupnumber, year=dataframe_equi$year, party_name = dataframe_equi$partyname, country = dataframe_equi$countryname, diff_in_pred_rile = effect)
dataframe_equi$jee <- el$diff_in_pred_rile

# sort counties by absolute value of the change in predicted rile
el <- el %>% group_by(year) %>% top_n(5)  %>%
ungroup() %>%
  arrange(year, diff_in_pred_rile) %>%
  mutate(order = row_number())

# plot the results
el$pes <- ifelse(el$groupnumber == 20, 1, 0)

ggplot(el, aes(y=diff_in_pred_rile, x=order, order, fill = as.factor(pes))) +
  geom_bar(stat = "identity") +
  ggtitle("") +
  xlab("") +
  ylab("") +
  theme_bw() +
  theme(panel.grid.major.x = element_blank(),
        axis.text.y=element_blank(),
        axis.ticks.y=element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.border = element_rect(colour = "black")) + facet_wrap(~ year, scales = "free_y") + scale_y_continuous(limits=c(-0.02, 0.02), breaks = c(-0.01, 0, 0.01)) +
  scale_fill_manual(values=c("gray80", "red"), name = "Member of Social Democratic \nTransnational Party Group", labels = c("no", "yes")) + coord_flip() +
  theme(plot.title = element_text(lineheight=.8)) +
  theme(axis.text=element_text(size=9)) + theme(legend.position = c(0.8, 0.05))

```

## Table S5 

```{r, eval = T, echo = T, include=TRUE}

# load dataset

load("./weight_matrices.RData")

#mean neighbors
mean(wmatnonaffiliated_ruled)*2718
mean(wmatinonaffiliated_ruled)*2718
mean(wmatknonaffiliated_ruled)*2718

```


## Table S6

```{r, eval = T, echo = T, include=TRUE}

# load dataset 

load("./dataframe1.RData")

# increase maximum print to show full regression outputs 

options(max.print=1000000)

# Model A1 in Table S6 

modela1 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spnonaffiliated_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 +  year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

modela1 <- lm(modela1, data = dataframe1)
summary(modela1)
stargazer(modela1)

# Model A2 in Table S6 

modela2 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spinonaffiliated_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

modela2 <- lm(modela2, data = dataframe1)
summary(modela2)
stargazer(modela2)

# Model A3 in Table S6 

modela3 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spknonaffiliated_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

modela3 <- lm(modela3, data = dataframe1)
summary(modela3)
stargazer(modela3)


```


## Table S7

```{r, eval = T, echo = T, include=TRUE}

# load dataset 

load("./dataframe_interpol.RData")

# increase maximum print to show full regression outputs 

options(max.print=1000000)

# Model LI1 in Table S7 

modelli1 <- as.formula(paste("rile.y.linear ~  spruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 +  year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

modelli1 <- lm(modelli1, data = dataframe_interpol)
summary(modelli1)
stargazer(modelli1)

# Model LI2 in Table S7

modelli2 <- as.formula(paste("rile.y.linear ~ rile.y.linear_lag + lag_cmedian + lag_econ_glob + interaction + spruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + 
year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

modelli2 <- lm(modelli2, data = dataframe_interpol)
summary(modelli2)
stargazer(modelli2)

# Model LI3 in Table S7

modelli3 <- as.formula(paste("rile.y.linear ~ spsamegroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

modelli3 <- lm(modelli3, data = dataframe_interpol)
summary(modelli3)
stargazer(modelli3)

# Model LI4 in Table S7

modelli4 <- as.formula(paste("rile.y.linear ~ rile.y.linear_lag + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + 
year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

modelli4 <- lm(modelli4, data = dataframe_interpol)
summary(modelli4)
stargazer(modelli4)


```

## Table S8

```{r, eval = T, echo = T, include=TRUE}

# load dataset 

load("./dataframe_spline.RData")

# increase maximum print to show full regression outputs 

options(max.print=1000000)

# Model LI1 in Table S7 

modelsi1 <- as.formula(paste("rile.y.spline ~  spruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 +  year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

modelsi1 <- lm(modelsi1, data = dataframe_spline)
summary(modelsi1)
stargazer(modelsi1)

# Model LI2 in Table S7

modelsi2 <- as.formula(paste("rile.y.spline ~ rile.y.spline_lag + lag_cmedian + lag_econ_glob + interaction + spruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + 
year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

modelsi2 <- lm(modelsi2, data = dataframe_spline)
summary(modelsi2)
stargazer(modelsi2)

# Model LI3 in Table S7

modelsi3 <- as.formula(paste("rile.y.spline ~ spsamegroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

modelsi3 <- lm(modelsi3, data = dataframe_spline)
summary(modelsi3)
stargazer(modelsi3)

# Model LI4 in Table S7

modelsi4 <- as.formula(paste("rile.y.spline ~ rile.y.spline_lag + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + 
year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

modelsi4 <- lm(modelsi4, data = dataframe_spline)
summary(modelsi4)
stargazer(modelsi4)


```

## Figure S4

```{r, eval = T, echo = T, include= T, message= FALSE, fig.width=8, fig.height=4}

# load dataset

load("./dataframe_its.RData")

#center time variable

dataframe_its$elapsed <-  scale(dataframe_its$year, center=TRUE, scale=FALSE)

# its model

model <- lm(dis_to_pes ~ elapsed + time + elapsed*time, data = dataframe_its)
summary(model)

# its results plot 

ggplot(dataframe_its_plot, aes(x=reorder(name, order), y=coefs)) + 
  geom_point(size=1, position=position_dodge(width=0.3), color = "gray50") +
  geom_errorbar(aes(ymin=lower, ymax=upper), color = "gray50", width=.01, position=position_dodge(width=0.3)) + 
  coord_flip() + theme_bw() + geom_hline(yintercept=0, linetype="dashed", 
                                         color = "gray50", size=0.5) +
  ylab("Coefficient") + xlab("") + theme(legend.title=element_blank()) +
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + ggtitle("Interrupted Time Series") +
  ylim(-1.25, 0.25)

```

## Table S9

```{r, eval = T, echo = T, include=TRUE}

# load dataset 

load("./dataframe1.RData")

# increase maximum print to show full regression outputs 

options(max.print=1000000)

# Model 1 in Table S9 

model1 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + lag_econ_glob*lag_rile + spruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + 
year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + 
year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model1 <- lm(model1, data = dataframe1)
summary(model1)
stargazer(model1) 

# Model 2 in Table S9 

model2 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + lag_econ_glob*lag_rile + spsamegroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model2 <- lm(model2, data = dataframe1)
summary(model2)
stargazer(model2) 

# Model 3 in Table S9 

model3 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + lag_econ_glob*lag_rile + spdiffgroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model3 <- lm(model3, data = dataframe1)
summary(model3)
stargazer(model3) 

# Model 4 in Table S9 

model4 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + lag_econ_glob*lag_rile + spsamegroup_ruled + spdiffgroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model4 <- lm(model4, data = dataframe1)
summary(model4)
stargazer(model4) 

```

## Table S10 

```{r, eval = T, echo = T, include=TRUE}

# load datasets 

load("./dataframe_eu.RData")
load("./dataframe_multicult.RData")
load("./dataframe_auth.RData")
load("./dataframe_eco.RData")
load("./dataframe_regu.RData")

# increase maximum print to show full regression outputs 

options(max.print=1000000)

model_eu <- as.formula(paste("euroscep ~ lag_euroscep + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled_euroscep + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +  " , paste(partyfx, collapse= "+")))

model_eu <- lm(model_eu, data = dataframe_eu)
summary(model_eu)

model_multicult <- as.formula(paste("multicult ~ lag_multicult + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled_multicult + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + 
year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + 
year_fe31 + year_fe32 + year_fe33 + year_fe34 +  " , paste(partyfx, collapse= "+")))

model_multicult <- lm(model_multicult, data = dataframe_multicult)
summary(model_multicult)
stargazer(model_multicult)

model_auth <- as.formula(paste("auth ~ lag_auth + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled_auth + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + 
year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + 
year_fe31 + year_fe32 + year_fe33 + year_fe34 +  " , paste(partyfx, collapse= "+")))

model_auth <- lm(model_auth, data = dataframe_auth)
summary(model_auth)
stargazer(model_auth)

model_eco <- as.formula(paste("eco ~ lag_eco + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled_eco + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + 
year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + 
year_fe31 + year_fe32 + year_fe33 + year_fe34 +  " , paste(partyfx, collapse= "+")))

model_eco <- lm(model_eco, data = dataframe_eco)
summary(model_eco)
stargazer(model_eco)


model_regu <- as.formula(paste("regu ~ lag_regu + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled_regu + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + 
year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 +  year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + 
year_fe31 + year_fe32 + year_fe33 + year_fe34 +  " , paste(partyfx, collapse= "+")))

model_regu <- lm(model_regu, data = dataframe_regu)
summary(model_regu)
stargazer(model_regu)


```


## Table S11

```{r, eval = T, echo = T, include=TRUE}

# load dataset 

load("./dataframe1.RData")

# increase maximum print to show full regression outputs 

options(max.print=1000000)

# capture all parties minus one from colnames to include party fixed effects in the models

partyfx <- paste(colnames(dataframe1[24:237]), sep="")

model1 <- as.formula(paste("rile ~ spruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse="+")))

model1 <- lm(model1, data = dataframe1)

model2 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 +  year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model2 <- lm(model2, data = dataframe1)

model3 <- as.formula(paste("rile ~ spsamegroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 +  year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model3 <- lm(model3, data = dataframe1)

model4 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model4 <- lm(model4, data = dataframe1)

bgtest(model1)
bgtest(model2)
bgtest(model3)
bgtest(model4)

``` 

## Figure S5

```{r, eval = T, echo = T, include= T, message= FALSE, fig.width=8, fig.height=4}

test_m1 <- acf(resid(model1), main = "Model 1")
test_m2 <- acf(resid(model2), main = "Model 2")
test_m3 <- acf(resid(model3), main = "Model 3")
test_m4 <- acf(resid(model4), main = "Model 4")

``` 


## Table S12 and S13

```{r, eval = T, echo = T, include= T, message= FALSE, fig.width=8, fig.height=4}


# Model 2 (add. lag) in Table S13 

model_lag2 <- as.formula(paste("rile ~ lag1_rile + lag2_rile + lag_cmedian + lag_econ_glob + interaction + spruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + 
year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + 
year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model_lag2 <- lm(model_lag2, data = dataframe1)
summary(model_lag2)
stargazer(model_lag2)

# Model 4 (add. lag) in Table S13 

model_lag4 <- as.formula(paste("rile ~ lag1_rile + lag2_rile + lag_cmedian + lag_econ_glob + interaction + spsamegroup_ruled + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + 
year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + 
year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model_lag4 <- lm(model_lag4, data = dataframe1)
summary(model_lag4)
stargazer(model_lag4)

# Table S12 

bgtest(model_lag2)
bgtest(model_lag4)


``` 

## Table S14

```{r, eval = T, echo = T, include= T, message= FALSE, fig.width=8, fig.height=4}

# load dataset 

load("./dataframe_opp.RData")


# Model OP1 in Table S14 

model_op1 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spnonincumbent + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + 
year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + 
year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))

model_op1 <- lm(model_op1, data = dataframe_opp)
summary(model_op1)
stargazer(model_op1)


# Model OP2 in Table S14 

model_op2 <- as.formula(paste("rile ~ lag_rile + lag_cmedian + lag_econ_glob + interaction + spnonincumbent_samegroup + year_fe2 + year_fe3 + year_fe4 +  year_fe5 + year_fe6 + 
year_fe7 +  year_fe8 +  year_fe9 +  year_fe10 + year_fe11 + year_fe12 + year_fe13 + year_fe14 + year_fe15 + year_fe16 + year_fe17 + year_fe18 + year_fe19 + year_fe20 + year_fe21 + year_fe22 + year_fe23 + year_fe24 + year_fe25 + year_fe26 + year_fe27 + year_fe28 + year_fe29 + year_fe30 + 
year_fe31 + year_fe32 + year_fe33 + year_fe34 +" , paste(partyfx, collapse= "+")))


model_op2 <- lm(model_op2, data = dataframe_opp)
summary(model_op2)
stargazer(model_op2)


``` 

